# Maintainer: Robin Broda <coderobe @ archlinux.org>
pkgname=nebula
pkgver=1.7.2
pkgrel=1
pkgdesc='A scalable overlay networking tool with a focus on performance, simplicity and security'
arch=(loong64 x86_64)
url='https://github.com/slackhq/nebula'
license=(MIT)
depends=(glibc)
makedepends=(go)
options=(!lto)
source=($pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz)
sha512sums=('b9b871eabdf0ffb05cb350fd665e4cc7c39c9c519837eb4aa88aba4d8d43d62e098da6eb4d2e679100eaa1755f1bb0a3d416a2ea5271ad1e841be1d3434fb341')
b2sums=('18f996e56aa4de44c8f45d5ad051a07f2927f8115c76ecce9be9dfe0a59f3b5175a93de8442f384162cf406298833d9a364f2ca5f9a51797961505368fe5d3d5')

prepare() {
  mkdir -vp $pkgname-$pkgver/build
}

build() {
  cd $pkgname-$pkgver

  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"
  export GOPATH="$srcdir"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"

  go build -ldflags "-X main.Build=$pkgver -compressdwarf=false -linkmode external" -o build ./cmd/...
}

check() {
  cd $pkgname-$pkgver

  go test -v ./...
}

package() {
  cd $pkgname-$pkgver

  install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -Dm644 dist/arch/nebula.service -t "$pkgdir/usr/lib/systemd/system/"
  install -vDm 755 build/* -t "$pkgdir/usr/bin/"
}
